﻿using AutoMapper;
using Domain.Flow;
using MediatR;
using U.B.DoMain.rabbitsAAA;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class AddPicACommandHander : IRequestHandler<AddPicACommand, ApiResult<object>>
    {
        public readonly IRepistory<PICA> _picARepository;
        public readonly IMapper _mapper;
        public AddPicACommandHander(IRepistory<PICA> picARepository, IMapper mapper)
        {
            _picARepository = picARepository;
            _mapper = mapper;
        }
        public Task<ApiResult<object>> Handle(AddPicACommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> result = new ApiResult<object>();
            var presult = _mapper.Map<PICA>(request);
            _picARepository.Add(presult);
            result.Data = presult;
            result.code = Renum.添加成功;
            result.Message = Renum.添加成功.ToString();
            return Task.FromResult(result);
        }
    }
}
